package com.icas.entity.resultentity;


import com.fasterxml.jackson.annotation.JsonInclude;
import com.icas.enums.MsgResultEnum;
import com.icas.enums.ShiroEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * @Author: tocchen
 * @Date: 2022/4/18 19:43
 * @Description
 **/
@Data
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class Result<T> implements Serializable {

    private Integer code;


    private String msg;

    private T data;

    private String token;



    private Result() {
    }


    private Result(MsgResultEnum msgResultEnum){
        this.code = msgResultEnum.getCode();
        this.msg = msgResultEnum.getMsg();
    }

    private Result(Integer code , String msg){
        this.code = code;
        this.msg = msg;
    }


    public Result(MsgResultEnum msgResultEnum, T data) {
        super();
        this.code = msgResultEnum.getCode();
        this.msg = msgResultEnum.getMsg();
        this.data = data;
    }

    public Result(MsgResultEnum msgResultEnum, T data, String token) {
        this.code = msgResultEnum.getCode();
        this.msg = msgResultEnum.getMsg();
        this.data = data;
        this.token = token;
    }

    public Result(T data){
        this();
        this.data = data;
    }



    public static Result<?> ok() {
        return new Result(MsgResultEnum.RESULT_SUCCESS);
    }



    public static<T> Result<?> oK(T data) {
        return new Result(MsgResultEnum.RESULT_SUCCESS,data);
    }
    public static<T> Result oK(T data,String token) {
        return new Result(MsgResultEnum.RESULT_SUCCESS,data,token);
    }


    public static Result error(MsgResultEnum msgResultEnum) {
        return new Result(msgResultEnum);
    }


    public static<T> Result error(MsgResultEnum msgResultEnum, T data) {
        return new Result(msgResultEnum,data);
    }


    public static Result error(ShiroEnum shiroEnum){ return new Result(shiroEnum.getCode(),shiroEnum.getMsg());  }

    public static Result error(Integer code ,String msg ){
        return new Result(code,msg);
    }
}
